<template>
  <div>
    <el-form :disabled="isEdit" ref="from" class="copyright" label-width="80px" :model="formLabelAlign" :rules="rules" status-icon>
      <el-row>
        <el-col :span="24">
          <h2 class="applyFor">申请作品上链</h2>
          <h4 class="caption">选择作品</h4>
          <p class="caption-out">如果进⾏上链审核的作品进⾏过上链，请选择对应的作品关联</p>
        </el-col> 
      </el-row>
      <el-row>
        <el-col :span="24">
            <el-form-item>
              <el-select v-model="formLabelAlign.workId" placeholder="无">
                <el-option
                  v-for="item in options"
                  :label="item.name"
                  :value="item.workId"
                  :key="item.workId">
                </el-option>
              </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <h4 class="caption">合约名称</h4>
        </el-col> 
      </el-row>
      <el-form-item>
        <el-input placeholder="请输入作品智能合约名称" class="inp" v-model="formLabelAlign.name"></el-input>
      </el-form-item>

      <el-row>
        <el-col :span="24">
          <h4 class="caption">链上简述</h4>
          <p class="caption-out">链上简述储存在智能合约中，可以通过区块链浏览器查看</p>
        </el-col> 
      </el-row>
      <el-form-item>
        <el-input placeholder="请输入作品链上简述" class="inp" v-model="formLabelAlign.chainDesc"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="presentCheck" class="el-submit">提交审核</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { addApply, getWorkList, detailWork } from '@/api/work'
export default {
  data(){
    return{
      formLabelAlign:{
        workId:undefined,
        name:'',
        chainDesc:'',
        payway:1,
        paytoken:'12345',
        identity:'identity123456',
      },
      isEdit: false,
      approve:'',
      rules:{},
      options: []
  }
},
  created(){
    this.getDataList();
    this.isEdit = (this.$route.query.isEdit=='true')
    if(this.$route.query.workId){
      this.getDetailWork();
    }
  },
  methods:{
    getDetailWork(){
      detailWork({
        workId: this.$route.query.workId
      }).then((res)=>{
        let data = res.data.data
        if (data.nft_apply) {
          this.formLabelAlign.workId = res.data.data.workId;
        this.formLabelAlign.name = data.nft_apply.name;
        this.formLabelAlign.chainDesc = data.nft_apply.chainDesc;
        }
        

      })
    },

    getDataList(){

      getWorkList({}).then((res)=>{

        this.options = res.data.workList.rows;
      })
    },
    // 提交审核
    presentCheck(){
      addApply(
        this.formLabelAlign
      ).then((res)=>{
        if(res.status == 200){
          this.$message.success("提交成功");
        }else{
          this.$message.error("提交失败");
        };
        this.$router.push('/cochain');
      });
    }
  },
  mounted(){
    
  }
 
}
</script>

<style scoped lang="less">
.copyright{
  .applyFor{
    margin-left: 80px;
  }
  .caption{
    margin-left: 80px;
    font-size: 18px;
  }
  .caption-out{
    margin-left: 80px;
    color: #959595;
  }
  .inp{
    width: 40%;
  }
  .el-submit{
    margin: 40px 0 0 0;
    width: 250px;
  }
}
</style>